package pl.pages;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.annotations.InitialValue;
import org.apache.tapestry.annotations.InjectState;
import org.apache.tapestry.html.BasePage;

import pl.model.Celebrity;

public abstract class Home extends BasePage {

	private Log log = LogFactory.getLog(this.getClass());
	
	@InitialValue("literal:enter a word")
	public abstract String getSecret();
	
	@InjectState("celebrityOfTheWeek")
	public abstract Celebrity getTheCelebrity();
	
	public Home() {
	}

	public Date getCurrentDate() {
		log.debug("getDate");
		return new Date();
	}

	public String getCurrentDateWithComment() {
		return new Date() + " - godzina "
				+ new GregorianCalendar().get(Calendar.HOUR);
	}
	
	public String validateSecret(IRequestCycle cycle){
		/*
		Secret page = (Secret) cycle.getPage("Secret");
		WebSession s = page.getEngine().getInfrastructure().getRequest().getSession(true);
		page.setSecret(getSecret());
		if (s.getAttribute("company")== null){
			s.setAttribute("company", new Company());
		} else {
			((Company) s.getAttribute("company")).incCounter();
		}
		log.debug("validateSecret " + getSecret());
		log.debug("counter: " + ((Company) s.getAttribute("company")).getCounter());
		*/
		return "Secret";
	}
	
	public String getFullName() {

		Celebrity c = getTheCelebrity();
		return c.getFirstName() + " " + c.getLastName();
	}
}
